package kr.pe.osdev.bbs.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import kr.pe.osdev.bbs.business.BbsDeletegate;
	import kr.pe.osdev.bbs.event.BbsListEvent;
	import kr.pe.osdev.bbs.model.BbsModelLocator;
	import kr.pe.osdev.bbs.vo.BbsListParams;
	
	import mx.controls.Alert;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	
	public class BbsListCommand  implements ICommand, IResponder{
		
		public function BbsListCommand(){
		}
		
		public function execute(event:CairngormEvent):void{
			var params : BbsListParams = BbsListEvent(event).params;
			var delegate:BbsDeletegate = new BbsDeletegate(this);
			delegate.selectList(params.searchType, params.searchKeyword, params.page, params.rowNum);
		}
		
		public function result(data:Object):void{
			var model : BbsModelLocator = BbsModelLocator.getInstance();
			
			model.bbsList = data.result;
			model.workflowState = BbsModelLocator.VIEWING_BBS_LIST;
		}
		
		public function fault(info:Object):void{
			var faultEvent : FaultEvent = FaultEvent(info);
			Alert.show("목록 가져오기가 실패 하였습니다." + faultEvent);
		}
	}
}